import { _decorator, Component, Node, Vec3 } from 'cc';
import { ActorManager } from '../level/ActorManager';
const { ccclass, property } = _decorator;

@ccclass('Camera')
export class Camera extends Component {
    private initDirection: Vec3 = null
    private tempPos: Vec3 = new Vec3()
    start() {

    }

    update(deltaTime: number) {
        let target = ActorManager.instance.playerActor
        if (!target) return
        if (!this.initDirection) {
            this.initDirection = new Vec3()
            //相机与角色之间的矢量
            Vec3.subtract(this.initDirection, this.node.worldPosition, target.node.position)
        } else {
            Vec3.add(this.tempPos, target.node.worldPosition, this.initDirection)
            this.node.worldPosition = this.tempPos
        }
    }

}


